xl: Implement per-API-call garbage-collection lifetime
authorGianni Tedesco <gianni.tedesco@citrix.com>
Thu, 12 Aug 2010 17:55:16 +0000 (18:55 +0100)
committerGianni Tedesco <gianni.tedesco@citrix.com>
Thu, 12 Aug 2010 17:55:16 +0000 (18:55 +0100)
commit94413e51b0558f0b55137328d51ce8c26dd358a0
tree1716442ff500684121d4da656788c812ce35606a
parentdb6b874fcd1430219176a4f86c2bf21dc4946388
xl: Implement per-API-call garbage-collection lifetime

Currently scratch variables allocated by libxl have the same lifetime as
the context. While this is suitable for one off invocations of xl. It is
not so great for a daemon process linking to libxl. In that case there
will be prolific leakage of heap memory.

My proposed solution involves create a new libxl_gc structure, which
contains a pointer to an owning context as well as the garbage
collection data. Top-level library functions which expect to do a lot of
scratch allocations put gc struct on the stack and initialize it with a
macro. Before returning they then call libxl_free_all on this struct.
This means that static helper functions called by such functions will
usually take a gc instead of a ctx as a first parameter.

The patch touches almost every code-path so a close review and testing
would be much appreciated. I have tested with valgrind all of the parts
I could which looked non-straightforward. Suffice to say that it seems
crash-free even if we have exposed a few real memory leaks. These are
for cases where we return eg. block list to an xl caller but there is no
appropriate block_list_free() function to call. Ian Campbells work in
this area should sew up all these loose ends.

Signed-off-by: Gianni Tedesco <gianni.tedesco@citrix.com>
committer: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
12 files changed:
tools/libxl/libxl.c
tools/libxl/libxl.h
tools/libxl/libxl_bootloader.c
tools/libxl/libxl_device.c
tools/libxl/libxl_dom.c
tools/libxl/libxl_exec.c
tools/libxl/libxl_internal.c
tools/libxl/libxl_internal.h
tools/libxl/libxl_pci.c
tools/libxl/libxl_utils.c
tools/libxl/libxl_xshelp.c
tools/libxl/xl_cmdimpl.c